package com.neborosoft.FlyingDog.logic.database.providers;

import com.neborosoft.FlyingDog.logic.database.AudioDataManager;
import com.neborosoft.lib.collections.tree.MultiStepsNavigationTree;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: CM
 * Date: 25.02.13
 * Time: 23:33
 * To change this template use File | Settings | File Templates.
 */
public abstract class TagsTreeWithSongsAndArtistsNavigation extends MultiStepsNavigationTree{
    private static final AudioDataManager AUDIO_DATA_MANAGER = AudioDataManager.getInstance();

    public static final int LEVELS_COUNT = 4;
    public static final int TAGS_LEVEL = 0;
    public static final int ARTISTS_LEVEL = 1;
    public static final int ALBUMS_LEVEL = 2;
    public static final int SONGS_LEVEL = 3;
    public static final int STEPS_COUNT_FROM_TAGS_TO_SONGS = 2;

    public TagsTreeWithSongsAndArtistsNavigation() {
        super(LEVELS_COUNT);
    }

    protected List getTracksByTag(String tagName){
        return AUDIO_DATA_MANAGER.getTracksByTag(tagName);
    }

    protected List getArtistsByTag(String tagName){
        return AUDIO_DATA_MANAGER.getArtistsByTag(tagName);
    }

    @Override
    protected List getChildrenOfParent(Object parent, int level, int stepsCount) {
        if(level != TAGS_LEVEL){
            return ArtistTree.getChildrenOfParentInArtistTree(parent, level - 1, stepsCount);
        }

        String tagName = parent.toString();
        if(stepsCount == STEPS_COUNT_FROM_TAGS_TO_SONGS){
            return getTracksByTag(tagName);
        } else {
            return getArtistsByTag(tagName);
        }
    }
}
